/**
 * @file test_tim.c
 * @author Jomb (jomb.liu@solinftec.com)
 * @brief 
 * @version 0.1
 * @date 2022-08-09
 * 
 * @copyright Copyright (c) 2022
 * 
 */

#include <rtthread.h>
#include <rtdevice.h>

#define PWM_DEV_NAME        "pwm3_dma_ch1" 

rt_device_t pwm_dma_dev;

uint32_t test_data[] = {900,900,900,900,900,900,900,900,900,900,900,900};
uint16_t dma_mem[sizeof(test_data)/sizeof(uint32_t)];

static int pwm_dma_sample(int argc, char *argv[])
{   
    
    struct rt_pwm_dma_configuration config; 
    static uint16_t init_flag = 0;
    
    if (init_flag == 0)
    {
        init_flag = 1;
        
        pwm_dma_dev = rt_device_find(PWM_DEV_NAME);
        if (pwm_dma_dev == RT_NULL)
        {
            rt_kprintf("pwm sample run failed! can't find %s device!\n", PWM_DEV_NAME);
            return RT_ERROR;
        }

        config.period = 1250;
        config.pulse = 1250;
        config.mem =  dma_mem;
        config.polarity = PWM_DMA_OCPOLARITY_LOW;
        
        rt_device_control(pwm_dma_dev,PWM_DMA_CMD_SET,(void *)&config);
        
        rt_device_open(pwm_dma_dev,RT_NULL);

    }
    
    rt_device_write(pwm_dma_dev,0,test_data,11);
    return 0;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(pwm_dma_sample, pwm sample);
